System and method for analyzing malicious code using a static analyzer

ABSTRACT

Analyzing computer code using a tree is described. For example, a client device generates a data request for retrieving data from a non-trusted entity via a network. A gateway is communicatively coupled to the client device and to the network. The gateway is configured to receive computer code from the non-trusted entity via the network. The gateway builds a tree representing the computer code. The tree has one or more nodes. A node of the tree represents a statement from the computer code. The gateway analyzes the statement to identify symbol data. The symbol data describes a name of the variable and the value of the variable. The gateway stores the symbol data in a symbol table.

CROSS REFERENCE

This application claims priority from the following U.S. provisional patent application, which is hereby incorporated by reference: Ser. No. 61/353,957, filed on Jun. 11, 2010, and entitled “Method and System for Detecting Malicious Content.”

BACKGROUND OF THE INVENTION

1. Field of the Invention

The present invention generally relates to malware detection and in particular to a static analyzer for analyzing malicious computer code.

2. Description of the Background Art

Computer networks and systems have become indispensable tools for modern data communication. Terabits of information are communicated by computer networks throughout the world. Much of this information is, to some degree, confidential and its protection is required. However, security threats have become increasingly able to evade conventional signature or pattern based detection techniques. This problem is enhanced with advent of widespread use of dynamic computer code such as JavaScript in websites. In addition to viruses, additional types of malicious software (“malware”), such as cross-site scripting and Trojans, have become increasingly common methods for impeding the performance of the client device and accessing sensitive information stored on client device.

More information about the malware is necessary to improve network security. It is therefore useful to acquire information describing computer code that is received from non-trusted entities.

SUMMARY OF THE INVENTION

Embodiments of the present invention provide a system and method analyzing computer code using a tree. A client device generates a data request for retrieving data from a non-trusted entity via a network. A gateway is communicatively coupled to the client device and to the network. The gateway is configured to receive computer code from the non-trusted entity via the network. The gateway builds a tree representing the computer code. The tree has one or more nodes. A node of the tree represents a statement from the computer code. The gateway analyzes the statement to identify symbol data. The symbol data describes a name of the variable and a value of the variable. The gateway stores the symbol data in a symbol table. In one embodiment, the gateway analyzes the statement to determine context data describing the scope of the variable. The gateway stores the context data in a context table.

The features and advantages described herein are not all-inclusive and many additional features and advantages will be apparent to one of ordinary skill in the art in view of the figures and description. Moreover, it should be noted that the language used in the specification has been principally selected for readability and instructional purposes, and not to limit the scope of the inventive subject matter.

BRIEF DESCRIPTION OF THE DRAWINGS

The invention is illustrated by way of example, and not by way of limitation in the figures of the accompanying drawings in which like reference numerals are used to refer to similar elements.

FIG. 1 is a block diagram of a system for using a static analyzer to analyze computer code according to one embodiment.

FIG. 2 is a block diagram of a client device according to one embodiment.

FIG. 3 is a block diagram of a gateway according to one embodiment.

FIG. 4 is a block diagram of a static analyzer according to one embodiment.

FIG. 5 is a flow chart of a method for using a static analyzer to analyze computer code according to one embodiment.

FIGS. 6A, 6B, 6C and 6D are a flow chart of a method for using a static analyzer to analyze computer code according to another embodiment.

DESCRIPTION OF EMBODIMENTS

A method and system for using a static analyzer to analyze computer code in accordance with the present invention is described below. In the following description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the invention. It will be apparent, however, to one skilled in the art that the invention can be practiced without these specific details. In other instances, structures and devices are shown in block diagram form in order to avoid obscuring the invention.

Reference in the specification to “one embodiment” or “an embodiment” means that a particular feature, structure, or characteristic described in connection with the embodiment is included in at least one embodiment of the invention. The appearances of the phrase “in one embodiment” in various places in the specification are not necessarily all referring to the same embodiment.

Some portions of the detailed descriptions that follow are presented in terms of algorithms and symbolic representations of operations on data bits within a computer memory. These algorithmic descriptions and representations are the means used by those skilled in the data processing arts to most effectively convey the substance of their work to others skilled in the art. An algorithm is here, and generally, conceived to be a self consistent sequence of steps leading to a desired result. The steps are those requiring physical manipulations of physical quantities. Usually, though not necessarily, these quantities take the form of electrical or magnetic signals capable of being stored, transferred, combined, compared, and otherwise manipulated. It has proven convenient at times, principally for reasons of common usage, to refer to these signals as bits, values, elements, symbols, characters, terms, numbers or the like.

It should be borne in mind, however, that all of these and similar terms are to be associated with the appropriate physical quantities and are merely convenient labels applied to these quantities. Unless specifically stated otherwise as apparent from the following discussion, it is appreciated that throughout the description, discussions utilizing terms such as “processing” or “computing” or “calculating” or “determining” or “displaying” or the like, refer to the action and processes of a computer system, or similar electronic computing device, that manipulates and transforms data represented as physical (electronic) quantities within the computer system's registers and memories into other data similarly represented as physical quantities within the computer system memories or registers or other such information storage, transmission or display devices.

The present invention also relates to an apparatus for performing the operations herein. This apparatus may be specially constructed for the required purposes, or it may comprise a general-purpose computer selectively activated or reconfigured by a computer program stored in the computer. Such a computer program may be stored in a computer readable storage medium, such as, but is not limited to, any type of disk including floppy disks, optical disks, CD-ROMs, and magnetic-optical disks, read-only memories (ROMs), random access memories (RAMs), EPROMs, EEPROMs, magnetic or optical cards, or any type of media suitable for storing electronic instructions, each coupled to a computer system bus.

The invention can take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment containing both hardware and software elements. In one embodiment, the invention is implemented in software, which includes but is not limited to firmware, resident software, microcode, etc.

Furthermore, the invention can take the form of a computer program product accessible from a computer-usable or computer-readable medium providing program code for use by or in connection with a computer or any instruction execution system. For the purposes of this description, a computer-usable or computer readable medium can be any apparatus that can contain, store, communicate, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device.

The medium can be an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system (or apparatus or device) or a propagation medium. Examples of a computer-readable medium include a semiconductor or solid state memory, magnetic tape, a removable computer diskette, a random access memory (RAM), a read-only memory (ROM), a rigid magnetic disk and an optical disk. Current examples of optical disks include compact disk-read only memory (CD-ROM), compact disk-read/write (CD-R/W) and DVD.

A data processing system suitable for storing and/or executing program code will include at least one processor coupled directly or indirectly to memory elements through a system bus. The memory elements can include local memory employed during actual execution of the program code, bulk storage, and cache memories which provide temporary storage of at least some program code in order to reduce the number of times code must be retrieved from bulk storage during execution.

Input/output or I/O devices (including but not limited to keyboards, displays, pointing devices, etc.) can be coupled to the system either directly or through intervening I/O controllers.

Network adapters may also be coupled to the system to enable the data processing system to become coupled to other data processing systems or remote printers or storage devices through intervening private or public networks. Modems, cable modem and Ethernet cards are just a few of the currently available types of network adapters.

Finally, the algorithms and displays presented herein are not inherently related to any particular computer or other apparatus. Various general-purpose systems may be used with programs in accordance with the teachings herein, or it may prove convenient to construct more specialized apparatus to perform the required method steps. The required structure for a variety of these systems will appear from the description below. In addition, the present invention is described with reference to a particular programming language. It will be appreciated that a variety of programming languages may be used to implement the teachings of the invention as described herein.

System Overview

FIG. 1 is a diagram of a system 100 for using a static analyzer to analyze computer code according to one embodiment. In the embodiment of FIG. 1, the system 100 includes a client device 110, a first server 120A, a second server 120B and a data source 140 exchanging data with each other via a network 130. Additionally, in the embodiment shown by FIG. 1, the client device 110 is coupled to a gateway 115, which is coupled to the network 130. Thy system 100 also includes a behavior server 150. In other embodiments, the system 100 includes additional and/or different components than the ones shown in FIG. 1.

The client device 110 is a computing device having data processing and communication capabilities. For example, a client device 110 comprises a desktop computer, a laptop computer, a netbook computer, a tablet computer, a smartphone or an internet capable television. While the system 100 shown by FIG. 1 includes a single client device 110, in other embodiments, the system 100 includes multiple client devices 110. For example, different types of client devices 110 are included in the system 100, such as a smartphone, a tablet computer and/or a laptop computer.

The client device 110 executes instructions or data using a processor to store, retrieve, modify or otherwise access data. When executing one or more processes, the client device 110 may access data from a remote source, such as a server 120 or another data source 140 via the network 130. To access remote data, the client device 110 transmits a data request to the server 120 or data source 140 via the network 130. The data request identifies the requested data as well as the client device 110 and may include additional information for identifying and retrieving the data.

A gateway 115 is coupled to the client device 110 and to the network 130 and receives one or more data requests from the client device 110. The gateway 115 communicates the data request to a first server 120A, a second server 120B or a data source 140 via the network 130. The gateway 115 receives data from one or more of the first server 120A, the second server 120B and the data source 140 via the network 130. For example, responsive to the data request, the gateway 115 receives data from one or more of the first server 120A, the second server 120B and the data source 140 via the network 130. The gateway 115 is a computing device that couples one or more client devices 110 to a network 130. For example, the gateway 115 is a router, a wireless access point, a network switch or any other suitable type of computing device. While FIG. 1 shows the gateway 115 as a separate component, in some embodiments the gateway 115 is included in the client device 110.

In addition to communicating data requests and data between a client device 110 and the first server 120A, the second server 120B and the data source 140, the gateway 115 also uses a static analyzer to analyze computer code. For example, the gateway 115 receives computer code from one or more of the data source 140, the first server 120A and the second server 120B. In one embodiment, the computer code is any routine and/or script received from the web application 122 and/or the data source 140. The gateway 115 analyzes the computer code, for example, to collect tree data describing the computer code.

Specifically, the gateway 115 parses the computer code to build a tree. For example, the gateway 115 parses the computer code to build an Abstract Syntax Tree (“AST” or “AST tree”). The AST tree is any form of AST tree. Each node of the tree includes one or more statements from the original computer code. In one embodiment, a node of the tree represents one or more statements occurring in the computer code. The gateway 115 stores a symbol table and a context table. The symbol table stores information describing one or more of the variables in the statement. For example, the gateway 115 parses a name and a value for a variable from the statement and stores the name and the value for the variable in the symbol table. The name and the value for the variable are referred to herein as “symbol data.” The context table stores information describing the scope the variable described by the symbol data in the symbol table.

In one embodiment, the symbol data describes each variable by the variable name and the value for the variable. The gateway 115 determines whether the variable is a control statement. If the variable is a control statement, the gateway 115 analyzes the variable to determine the scope of the variable. The gateway 115 stores information describing the scope of the variable in a context table. The information describing the scope of the variable is referred to herein as “context data.” In one embodiment, the symbol data for a variable is associated with a corresponding entry of context data stored in the context table. This association is stored in one or more of the symbol table and the context table. In another embodiment, the symbol table can have a variable name stored in it more than once, and the scope data stored in the context table (sometimes referred to as context data) can be used to differentiate the commonly named variables in the symbol table.

The gateway 115 analyzes the nodes of the tree to build and update the symbol table and the context table. This is described in further detail with reference to FIGS. 5 and 6A-6D.

The gateway 115 determines whether the one or more statements are simple statements. In one embodiment, a simple statement is a statement consisting of basic algebraic operators or intrinsic language functions. Simple statements are described in more detail below with reference to FIGS. 4, 5 and 6A-6D. Responsive to determining that a statement is a simple statement, the gateway 115 executes the statement. The gateway 115 analyzes the execution of the simple statement and updates the symbol table and the context table with additional information describing the one or more variables of the simple statement and the scope of the one or more variables. For example, the gateway 115 analyzes changes in the values of a variable that occur responsive to executing the statement. These changes to the value are described by value data indicating the new value for the variable. The gateway 115 tracks these changes and updates the symbol table by the value data describing the new value in the symbol table. The gateway 115 also tracks the changes to the statement scope. The gateway 115 updates the context table by storing context data describing the changes to the statement scope in the context table.

In one embodiment, the gateway 115 monitors the executed statement for behavior indicating that the statement is a component of malicious computer code. As used herein, the term “malicious computer code” refers to computer code that is associated with malware or that otherwise seeks to impair performance of the client device 110 and/or gateway 115, or transmit data from the client device 110 and/or gateway 115 without authorization.

The server 120A comprises a web application 122. The web application is code and routines that, when executed by a processor of the server 120A (the processor is not pictured), causes the web application to transmit computer code to the client device 110. In one embodiment, the computer code is any routine and/or script received from the web application 122 and/or the data source 140. For example, the computer code is a script or routine written in JavaScript, Hypertext Transfer Protocol, Cascading Style Sheets, etc. In another embodiment, the computer code is malicious. The computer code is intercepted by the gateway 115. The gateway 115 performs steps described below with reference to FIGS. 5 and 6A-6D to analyze and collect data describing the computer code and/or determine whether the computer code is exhibiting behavior indicating that the computer code is malicious.

The network 130 is a conventional network and may have any number of configurations such as a star configuration, a token ring configuration or another configuration known to those skilled in the art. In various embodiments, the network 130 is a wireless network, a wired network or a combination of a wireless and a wired network. Furthermore, the network 130 may be a local area network (LAN), a wide area network (WAN) (e.g., the Internet) and/or any other interconnected data path across which multiple devices may communicate. In yet another embodiment, the network 130 may be a peer-to-peer network.

The network 130 may also be coupled to, or include, portions of a telecommunications network for communicating data using a variety of different communication protocols. In yet another embodiment, the network 130 includes a Bluetooth communication network and/or a cellular communications network for sending and receiving data (e.g., 3G and/or 4G network). For example, the network 130 transmits and/or receives data using one or more communication protocols such as short messaging service (SMS), multimedia messaging service (MMS), hypertext transfer protocol, direct data connection, WAP, email or another suitable communication protocol.

A server 120 or a data source 140 is a computing device including data processing and communication capabilities. For purposes of illustration, FIG. 1 illustrates a system 100 including a first server 120A and a second server 120B; however, in other embodiments, the system 100 includes any number of servers 120. For example, a server 120 includes a processor, a communication unit and a storage device. However, in other embodiments, a server 120 may include different and/or additional components. A server 120 receives a data request from a client device 110 and transmits data to the client device 110 via the network 130. In one embodiment, a server 120 generates data or modifies data responsive to the data request. Different processes executed by the client device 110 may generate data requests for different servers 120. For example, a first process executed by the client device 110 generates a data request that is communicated to a first server 120A, while a second process executed by the client device 110 generates a data request that is communicated to a second server 120B.

In one embodiment, the system 100 includes a behavior server 150 coupled to the gateway 115 and/or the client device 110 via the network 130. The behavior server 150 is a computing device having data processing and data communication capabilities that includes data describing malicious data requests or data requests associated with malware (e.g., malicious computer code). In one embodiment, the behavior server 150 stores attributes of malicious computer code in a database. The database is communicated from the behavior server 150 to the gateway 115, which subsequently compares attributes of computer code intercepted by the gateway 115 from one or more of the non-trusted devices (e.g., server 120A, 120B and data source 140) with the database to identify malicious computer code. In one embodiment, malicious compute code is computer code that makes data requests that will harm the client device 110 and/or the gateway 115, or attempts unauthorized transmission of data stored on storage device associated with the client device 110 and/or gateway 115 to a non-trusted device. Additionally, the behavior server 150 communicates with the gateway 115 or the client device 110 via the network 130 to update the database, allowing the gateway 115 to use the most current data for identifying malicious computer code. For example, the behavior server 150 transmits an updated database to the gateway 115 or to the client device 110 when additional attributes of malicious computer code are identified.

For example, the behavior server 150 executes malware in one or more virtual machines and captures the data requests generated by the malware. The behavior server 150 then analyzes the data requests to identify one or more attributes of data requests produced by the executing malware. For example, the behavior server 150 identifies a User-Agent, a Computer Name, a Media Access Control Address, a Uniform Resource Indicator and/or a file name from the data requests generated by the malware and analyzes one or more of the attributes generated by different malware to determine characteristics of malicious data requests based on the different types of generated data requests. In one embodiment, the behavior server 150 generates one or more rules identifying attributes of malicious data requests based on analysis of the malicious data requests generated by multiple executing malware. Thus, the rules generated by the behavior server 150 specify attributes indicative of malicious data requests.

For example, the behavior server 150 analyzes the User Agent portion of data requests to identify User Agent portions commonly associated with malicious data requests. The User Agent portion of a data request is a text string that is sent from a client device 110 to a server 120 identifying the process or application generating the data request. In one embodiment, the behavior server 150 includes a blocking listing of User Agent data associated with malicious data requests, such as User Agent data used by different malware. This blocking listing is communicated to the gateway 115 and when the gateway 115 receives a data request including a User Agent portion matching an entry in the blocking listing, the data request is blocked. Alternatively, the behavior server 150 includes an authorized listing including User Agent data associated with legitimate processes. In one embodiment, the authorized listing is communicated to a gateway 115 to allow the gateway 115 to block a data request including a User Agent portion not included in the authorized listing. Alternatively, the behavior server 150 includes both a blocking listing and an authorized listing and communicates both the blocking listing and the authorized listing to a gateway 115. Additional examples of rules generated by the behavior server 150 and used by the gateway 115 to identify malicious data requests are further described below in conjunction with FIGS. 5 and 6A-6D.

Client Device 110

FIG. 2 is a block diagram of a client device 110. The client device 110 comprises a processor 220, a memory 216, a storage device 202 (sometimes referred to herein as “storage 202”) and a browser 210 stored on the storage device 202.

The processor 220, memory 216, storage device 202 and browser 210 are communicatively coupled to one another via a bus 205. The processor 220 is communicatively coupled to the bus 205 via signal line 255. The memory 216 is communicatively coupled to the bus 205 via signal line 265. The storage device 202 is communicatively coupled to the bus 205 via signal line 275. The browser 210 communicates with the other elements of the client device 110 via the signal line 275.

The processor 220 comprises an arithmetic logic unit, a microprocessor, a general purpose controller or some other processor array to perform computations and provide electronic display signals to a display device. The processor 220 is coupled to the bus 205 for communication with the other components. Processor 220 processes data signals and may comprise various computing architectures including a complex instruction set computer (CISC) architecture, a reduced instruction set computer (RISC) architecture, or an architecture implementing a combination of instruction sets. Although only a single processor is shown in FIG. 2, multiple processors may be included. The processing capability may be limited to supporting the display of images and the capture and transmission of images. The processing capability might be enough to perform more complex tasks, including various types of feature extraction and sampling. It will be obvious to one skilled in the art that other processors, operating systems, sensors, displays and physical configurations are possible.

The memory 216 stores instructions and/or data that may be executed by processor 220. The memory 216 is coupled to the bus 205 for communication with the other components. The instructions and/or data may comprise code for performing any and/or all of the techniques described herein. The memory 216 may be a dynamic random access memory (DRAM) device, a static random access memory (SRAM) device, flash memory or some other memory device known in the art. In one embodiment, the memory 216 also includes a non-volatile memory or similar permanent storage device and media such as a hard disk drive, a floppy disk drive, a CD-ROM device, a DVD-ROM device, a DVD-RAM device, a DVD-RW device, a flash memory device, or some other mass storage device known in the art for storing information on a more permanent basis.

The storage device 202 is a non-transitory computer-readable memory configured to store computer code. For example, the storage device 202 is a non-volatile storage medium such as a hard drive, flash memory, etc. The storage device 202 stores the browser 210. The processor 220 accesses and executes the browser 210.

The browser 210 is a web browser stored on the on the storage device 202 and configured for two-way communication with the gateway 115. For example, the browser 210 is a software application such as Mozilla FireFox, Windows Internet Explorer, Google Chrome, Apple Safari, Opera, etc. In one embodiment, the browser 210 communicates with the network 130 via the gateway 115.

Gateway 115

FIG. 3 is a block diagram of one embodiment of a gateway 115. In the embodiment shown by FIG. 3, the gateway 115 includes a processor 310, a storage device 320, a communication device 330 and a detection module 340 communicatively coupled to each other via a bus 305. However, in other embodiments, the gateway 115 includes different and/or additional components than the ones shown by FIG. 3. The processor 310 is communicatively coupled to the bus 305 via signal line 355. The storage device 320 is communicatively coupled to the bus 305 via signal line 365. The communication device 330 is communicatively coupled to the bus 305 via signal line 375.

The processor 310 is an arithmetic logic unit, a microprocessor, a general purpose controller or some other processor array to perform computations or other data processing that is coupled to the bus 305 for communication with the other components of the gateway 115. The processor 310 provides similar functionality as the processor 220 described above with reference to FIG. 2, so that description will not be repeated here.

The storage device 320 is a non-transitory computer-readable memory that stores instructions and/or data that may be executed by processor 310. The stored instructions and/or data may be code for performing any and/or all of the functionality described herein when executed by the processor 310. For example, the storage device 320 includes instructions that, when executed by the processor 310, cause the processor 310 to execute the steps further described below in conjunction with FIGS. 5 and 6A-6D. In one embodiment, the storage device 320 is a non-volatile memory device or similar persistent storage device and media. For example, the storage device 320 may be a hard disk drive, a floppy disk drive, a CD-ROM device, a DVD-ROM device, a DVD-RAM device, a DVD-RW device, a flash memory device or another mass storage device known in the art. In one embodiment, the storage device 320 comprises a dynamic random access memory (DRAM) device, a static random access memory (SRAM) device, flash memory or some other memory device known in the art. In another embodiment, the storage device 320 comprises a combination of persistent memory and non-persistent memory. The storage device 320 is coupled to the bus 305 to communicate with other components of the gateway 115.

In one embodiment, the storage device 320 stores a tree builder 322, a static analyzer 324, a behavior store 326 and tree data 328. In another embodiment, the tree builder 322 is included in the static analyzer 324 so that the tree builder 322 is an element of the static analyzer 324. For example, the tree builder 322 is a parser and the static analyzer 324 is a specially configured compiler that includes the tree builder 322 as a parser element of the compiler. In another embodiment, the tree builder 322 and the static analyzer 324 are each elements of a specially configured compiler that semi-analyzes and semi-executes computer code to determine information included in the tree data 328.

The tree builder 322 is a parser that, when executed by the processor 310, pareses the computer code received from the web application 122 and/or the data source 140 and builds a tree based at least in part on the computer code. In one embodiment, the tree builder 322 builds an AST tree. In other embodiments, the tree builder 322 builds another type of tree-based data structure. The tree builder 322 stores the tree on a non-transitory memory such as the storage device 320. For example, the tree is stored in the tree data 328.

In one embodiment, each node of the tree includes one or more statements from the original computer code. In another embodiment, a node of the tree corresponds to a construct occurring in the computer code.

In one embodiment, the tree built by the tree builder 322 is a binary representation of the computer code. A human user or processor-executed computer program (e.g., a compiler) can directly map the tree to the computer code. A human user or processor-executed computer program can also map the computer code back to the tree built by the tree builder 322. For example, the tree can be mapped to the computer code based at least in part on the binary representation present in the tree. In one embodiment, the tree builder 322 does not build the tree using machine code. Instead, the tree builder 322 builds the tree using any normalized representation of the computer code that is executable by the processor 310 and/or understandable by the static analyzer 324.

In one embodiment, the tree builder 322 embeds one or more probes in the tree. The probe is a function that is communicatively coupled to call the static analyzer 324 and provide information to the static analyzer 324, the client device 110 or some other trusted device describing the progress of analyzing the computer code or a subset of the computer code. For example, the probe is communicatively coupled to the static analyzer 324 to provide the static analyzer 324 with information describing the progress of the static analyzer 324 in analyzing the computer code. The probe is described in greater detail with reference to FIGS. 6A-6D.

In one embodiment, the tree builder 322 is a compiler that parses the computer code received from the web application 122 and/or the data source 140 and builds a tree based at least in part on the computer code.

In another embodiment, the tree builder 322 is a combination of a lexical analyzer and a parser that, when executed by the processor 310, builds a tree representing the computer code.

The static analyzer 324 is code and routines that, when executed by the processor 310, analyzes the tree built by the tree builder 322. For example, the static analyzer 324 is a specially configured compiler that, when executed by the processor 310, analyzes the tree to build and update the symbol table and the context table. The static analyzer 324 is configured to walk one or more nodes of the tree and analyze the one or more nodes. In one embodiment, each node of the tree has one or more statements parsed from the computer code by the tree builder 322 and the static analyzer 324 analyzes these statements. The static analyzer 324 builds and/or updates the symbol table and the context table. The symbol table and the context table are described above with reference to FIG. 1, so that description will not be repeated here. The static analyzer 324 determines if the one or more statements are simple. If the statements are simple the static analyzer 324 executes them and further updates the symbol table and/or the context table (e.g., with updated value data and/or context data). The static analyzer 324 is described in more detail with reference to FIGS. 4, 5 and 6A-6D.

The tree data 328 is data including the symbol table and the context table. The tree data is described in more detail below with reference to FIG. 4.

In one embodiment, the storage device 320 includes a behavior store 326 and a detection module 340. The behavior store 326 includes one or more rules identifying attributes of malicious data requests. For example, the behavior store 326 includes a rule identifying data requests including a Media Access Control (MAC) as malicious, as most known processes do not include a MAC address in a data request. As another example, the behavior store 326 includes a listing of suspicious uniform resource indicators (URIs) for identifying malicious data requests based on a URI included in the data request. As yet another example, the behavior store 326 includes a listing of one or more file names associated with malware, so that data requests including a reference to a listed file name are identified as malicious.

In one embodiment, the behavior store 326 also includes rules identifying attributes or properties of malicious data received from a server 120 or data source 140 in response to a data request. For example, the behavior store 326 associates types of responses from a server 120 or data source 140 with malicious data requests to aid in identification of malicious data requests. In one embodiment, if the server 120 or data source 140 returns less data than an amount of data associated with benign data requests, the behavior store 326 indicates that the data request prompting data transmission is malicious. Similarly, the behavior store 326 associates a data request prompting receipt of a fake error message from a server 120 as a malicious data request. Classifying data requests based on attributes of the received data as well as attributes of the corresponding data request allows the gateway 115 to more accurately identify malicious data requests.

The detection module 340 extracts attributes from a received data request and/or from received data and compares the extracted attributes to the contents of the behavior store 326. In one embodiment, the detection module 340 parses a data request into different attributes and compares at least a subset of the attributes to rules stored by the behavior store 326. In another embodiment, the detection module 340 extracts a subset of attributes of a data request and/or of received data and determines whether the subset of attributes are associated with malicious data requests based on the one or more rules stored in the behavior store 326. In yet another embodiment, the detection module 340 also extracts a subset of the data received by the gateway 115 responsive to a data request and compares the extracted subset of the received data to the content of the behavior store 326 to further determine whether the data request is malicious. The functionality of the behavior store 326 and the detection module 340 is further described below in conjunction with FIGS. 5 and 6A-6D.

The communication device 330 receives data requests from a client device 110 and transmits the data request to a server 120 or a data source 140 via the network 130. The communication device 330 also receives data from the server 120 or from the data source 140 via the network 130 and communicates the data to the client device 110. In one embodiment, the communication device 330 includes a port for direct physical connection to the network or to another communication channel. For example, the communication device 330 includes a USB, SD, CAT-5 or similar port for wired communication with the network. In another embodiment, the communication device 330 includes a wireless transceiver for exchanging data with the network, or with another communication channel, using one or more wireless communication methods, such as IEEE 802.11, IEEE 802.16, BLUETOOTH® or another suitable wireless communication method.

In yet another embodiment, the communication device 330 includes a cellular communications transceiver for sending and receiving data over a cellular communications network such as via short messaging service (SMS), multimedia messaging service (MMS), hypertext transfer protocol (HTTP), direct data connection, WAP, e-mail or another suitable type of electronic communication. In still another embodiment, the communication device 330 includes a wired port and a wireless transceiver. The communication device 330 also provides other conventional connections to the network for distribution of files and/or media objects using standard network protocols such as TCP/IP, HTTP, HTTPS and SMTP as will be understood to those skilled in the art.

Static Analyzer 324

FIG. 4 is a block diagram of one embodiment of a static analyzer 324. The static analyzer 324 comprises a tree walker 410 and a statement tester 430. The tree walker 410 and the statement tester 430 are communicatively coupled to one another via a bus 405. The bus 405 is also communicatively coupled to the tree data 328. The tree walker 410 and the statement tester 430 store and access data in the tree data via the bus 405. The tree walker 410 is communicatively coupled to the bus 405 via signal line 455. The statement tester 430 is communicatively coupled to the bus 405 via signal line 475. The tree data 328 is communicatively coupled to the bus 405 via signal line 465.

The tree walker 410 is code and routines that, when executed by the processor 310, walks and analyzes one or more nodes of the tree built by the tree builder 322. For example, the tree walker 410 is code and routines configured to walk the tree built by the tree builder 322 using one or more of a tree grammar, a manual tree walker and an abstract syntax tree walker. In one embodiment, the tree walker 410 includes the functionality of a parser. In another embodiment, the tree walker 410 includes the functionality of a compiler that includes a parser.

In one embodiment, each node of the tree has a statement parsed from the computer code by the tree builder 322. For each node walked, the tree walker 410 parses the statement to identity one or more of the variables in the statement. The tree walker 410 determines whether the identified variable is already stored in the symbol table 422. The tree walker 410 stores the variable and the value for the variable in the symbol table 422 responsive to determining that the variable is not already stored in the symbol table 422. The tree walker 410 updates the value for the variable in the symbol table 422 responsive to determining that the variable is already stored in the symbol table 422.

Next the tree walker 410 determines whether the statement is a control structure. If the statement is a control structure, the tree walker 410 determines the scope of the control structure. Responsive to determining that the statement is a control structure, the tree walker 410 further updates the context table 424 with context data describing the scope of the control structure. If the statement is not a control structure, the tree walker 410 does not update the context table 424. Instead, the tree walker 410 determines whether or not a probe function is included in the statement. The tree walker 410 calls the probe responsive to determining that a probe function is included in the statement.

The tree walker 410 determines whether the statement is completed. A statement is completed if the scope of the statement has been met (e.g., if the life of statement scope is expired). If the statement is completed, the tree walker 410 resets the statement scope. If the statement is not completed (i.e., the scope of the statement has not been met), the tree walker 410 updates the context table 424 with scope data describing the current scope of the statement and the statement's sub-statements (if any).

The tree walker 410 determines if a probe function is installed at the node. If a probe is installed, the tree walker 410 calls the probe.

The tree walker 410 analyzes the statement to determine if it is a simple statement. In one embodiment, a simple statement is a statement that only includes one or more basic language operators (e.g., plus, minus, etc.) applied to one or more variables. In one embodiment, a simple statement is a statement that only includes one or more function codes provided by the language in which the computer code is written. For example, the computer code is written in JavaScript and the statement includes one or more JavaScript functions. In one embodiment, if a statement includes any custom functions provided by a human user, then the statement is not simple. For example, if a statement includes one or more user-defined functions, then the statement is not simple since a simple statement is a statement that does not include any user-defined functions. If the statement is a simple statement, the tree walker 410 communicates with the statement tester 430 to indicate that the statement should the tested. After testing the statement is completed, the tree walker 410 updates the symbol table 422 and the context table 424 to include information describing the observed variables and the associated scope of these variables. For example, the tree walker 410 updates the symbol table 422 and the context table 424 as described below for FIGS. 6C and 6D.

The statement tester 430 is code and routines that, when executed by the processor 310, executes the statement. The statement tester 430 communicates with the tree walker 410 to signal to the tree walker 410 to update the symbol table 422 and the context table 424 responsive to executing the statement. In one embodiment, the statement tester 430 communicates to the detection module 340 to monitor for suspicious behavior by the statement responsive to executing the statement.

In one embodiment, upon execution by the processor 310, tree builder 322, tree walker 410, statement tester 430 and the detection module 340 provide the functionality described below with reference to FIGS. 5 and 6A-6D.

The symbol table 422 and the context table 424 are stored on the storage device 320. The symbol table 422 and the context table 424 are described above, so that description will not be repeated here.

Methods

FIG. 5 is a flow chart of a method 500 for using a static analyzer 324 to analyze computer code. The client device 110 makes a request to the web application 122. The web application 122 transmits computer code to the client device 110. For example, the web application 122 transmits a dynamic script (e.g., JavaScript, Hypertext Transfer Protocol, etc) to the client device 110. The gateway 115 intercepts the computer code. The tree builder 322 builds a tree 510 representing the computer code. The tree builder 322 communicates with the static analyzer 324 to begin walking the tree. In one embodiment, each node of the tree includes one or more statements parsed by the tree builder 322 from the computer code. The static analyzer 324 determines 520 whether all the nodes of the tree are walked. If all the nodes of the tree are walked, the static analyzer 324 ends the method 500. If all of the nodes of the tree are not walked, the method 500 moves to step 530 and the static analyzer 324 walks to the next un-walked node. The static analyzer 324 analyzes 540 the node and updates the symbol table 422 and/or the context table 424. The static analyzer 324 executes a statement and communicates with the detection module 340 to determine whether the executed statement exhibits suspicious behavior. The detection module 340 determines 550 whether the executed statement exhibited suspicious behavior. If the detection module 340 determines 550 that the executed statement did not exhibit suspicious behavior, the method 500 returns to step 520. If the detection module 340 determines 550 that the executed statement did exhibit suspicious behavior, the method 500 moves to step 560 and the gateway 115 blocks the computer code.

FIG. 6 is a flow chart of a method 600 for using a static analyzer 324 to analyze computer code. The client device 110 makes a request to the web application 122. The web application 122 transmits computer code to the client device 110. For example, the web application 122 transmits a dynamic script (e.g., JavaScript, Hypertext Transfer Protocol, etc) to the client device 110. The gateway 115 intercepts the computer code. The tree builder 322 builds a tree representing the computer code. The tree builder 322 communicates with the static analyzer 324 to begin walking the tree. The tree walker 410 initiates 610 walking a tree built by the tree builder 322. For each node walked, the tree walker 410 parses the statement to identify 612 one or more of the variables in the statement. The tree walker 410 determines 614 whether the identified variable is already stored in the symbol table 422. The tree walker 410 stores 616 the variable name and the value for the variable in the symbol table 422 responsive to determining that the variable is not already stored in the symbol table 422. The tree walker 410 updates 618 the value for the variable in the symbol table 422 responsive to determining that the variable is already stored in the symbol table 422.

At step 620, the tree walker 410 determines whether the statement is a control structure. If the statement is not a control structure, the method 600 proceeds to step 622 and the tree walker 410 does not update the context table 424. Instead, the method 600 advances to step 660 (step 660 is described below). If the statement is a control structure, the method 600 proceeds to step 624 and the tree walker 410 determines the scope of the control structure and updates the context table 424 with context data describing the scope of the control structure.

At step 630, the tree walker 410 determines whether the statement is completed. A statement is completed if the scope of the statement has been met (e.g., if the life of statement scope is expired). If the statement is completed, the method 600 proceeds to step 650 and the tree walker 410 resets the statement scope to the original value based at least in part on the scope of the variable to which the statement belongs as indicated by the context table 424. The method 600 advances to step 660 (step 660 is described below).

If the statement is not completed (i.e., the scope of the statement has not been met), the method 600 proceeds to step 640 and the tree walker 410 does not reset the current statement scope. Instead, the method 600 proceeds to step 652 and the tree walker 410 updates the context table 424 with scope data describing the current scope of the statement and the statement's sub-statements (if any).

The method proceeds to step 660. At step 660, the tree walker 410 determines if a probe function (“a probe”) is installed at the node. If a probe is not installed, the method 600 proceeds to step 662 and the tree walker 410 does not call a probe. If a probe is installed, the method 600 advances to step 664 and the tree walker 410 calls the probe.

At step 670, the tree walker 410 analyzes the statement to determine if it is a simple statement. If the tree walker 410 determines that statement is not a simple statement, the method moves to step 696. At step 696, the tree walker 410 determines whether all the nodes of the tree are walked. If all the nodes of the tree are walked, the method ends. If all of the nodes of the tree are not walked, the method 600 moves to step 698 and the tree walker 410 walks to the next un-walked node. The method then returns to step 612. If the statement is a simple statement, the method 600 moves to step 674 and the tree walker 410 communicates with the statement tester 430 to indicate that the statement should be tested by the statement tester 430. The statement tester 430 communicates with the tree walker 410 to indicate that the statement is about to be executed.

The statement tester 430 executes 674 the statement. In one embodiment, executing the statement reveals the actual variable names, values and scopes. The tree walker 410 identifies 676 one or more variable names. At step 678, the tree walker 410 determines whether the identified variable is already stored in the symbol table 422. The tree walker 410 stores 680 the variable name and the value for the variable in the symbol table 422 responsive to determining that the variable is not already stored in the symbol table 422. The tree walker 410 updates 682 the value for the variable in the symbol table 422 responsive to determining that the variable is already stored in the symbol table 422.

At step 684, the tree walker 410 determines whether the statement is a control structure. If the statement is not a control structure, the method 600 proceeds to step 685 and the tree walker 410 does not update the context table 424. If the statement is a control structure, the method 600 proceeds to step 686 and the tree walker 410 determines the scope of the control structure and updates the context table 424 with context data describing the scope of the control structure.

Contemporaneous to execution of the statement (e.g., step 674), the static analyzer 324 communicates with the detection module 340 to indicate to the detection module 340 that the statement will be executed. At step 688, the detection module 340 analyzes the behavior of the executed statement using the data stored in the behavior store 326. The detection module 340 determines 690 whether the executed statement exhibited suspicious behavior. If no suspicious behavior is detected by the detection module 340, the method returns to step 696. If suspicious behavior is detected by the behavior module 340, the method 600 goes to step 694. At step 694, the method 600 either returns to step 696 or blocks the computer code (e.g., based on input received from a human administrator of the gateway 115).

The foregoing description of the embodiments of the present invention has been presented for the purposes of illustration and description. It is not intended to be exhaustive or to limit the present invention to the precise form disclosed. Many modifications and variations are possible in light of the above teaching. It is intended that the scope of the present invention be limited not by this detailed description, but rather by the claims of this application. As will be understood by those familiar with the art, the present invention may be embodied in other specific forms without departing from the spirit or essential characteristics thereof. Likewise, the particular naming and division of the modules, routines, features, attributes, methodologies and other aspects are not mandatory or significant, and the mechanisms that implement the present invention or its features may have different names, divisions and/or formats. Furthermore, as will be apparent to one of ordinary skill in the relevant art, the modules, routines, features, attributes, methodologies and other aspects of the present invention can be implemented as software, hardware, firmware or any combination of the three. Also, wherever a component, an example of which is a module, of the present invention is implemented as software, the component can be implemented as a standalone program, as part of a larger program, as a plurality of separate programs, as a statically or dynamically linked library, as a kernel loadable module, as a device driver, and/or in every and any other way known now or in the future to those of ordinary skill in the art of computer programming. Additionally, the present invention is in no way limited to implementation in any specific programming language, or for any specific operating system or environment. Accordingly, the disclosure of the present invention is intended to be illustrative, but not limiting, of the scope of the present invention, which is set forth in the following claims. 

1. A system for analyzing computer code comprising: a client device generating a data request for retrieving data from a non-trusted entity via a network; and a gateway communicatively coupled to the client device and to the network, the gateway configured to receive computer code from the non-trusted entity via the network, build a tree representing the computer code, a node of the tree having a statement from the computer code, analyze the statement to identify symbol data describing a variable, the symbol data describing a name of the variable and a value of the variable, and store the symbol data in a symbol table.
 2. The system of claim 1, wherein the gateway is further configured to determine context data describing a scope of the statement and storing the context data in a context table.
 3. The system of claim 2, wherein the symbol data stored in the symbol table is associated with the context data stored in the context table.
 4. The system of claim 1, wherein the gateway is further configured to embed a probe function in the node of the tree, detect the probe function and call a probe responsive to detecting the probe function in the node.
 5. The system of claim 1, wherein the gateway is further configured to determine whether the statement is a simple statement and execute the statement responsive to determining that the statement is the simple statement.
 6. The system of claim 5, wherein the simple statement includes one or more of a basic language operator applied to the variable and a function code intrinsic to a language in which the computer code is written.
 7. The system of claim 5, wherein the gateway is further configured to analyze the executed statement to identify modifications to the symbol data stored in the symbol table and update the symbol data stored in the symbol table responsive to analyzing the executed statement.
 8. The system of claim 2, wherein the gateway is further configured to determine whether the statement is a simple statement, execute the statement responsive to determining that the statement is the simple statement, analyze the executed statement to identify modifications to the symbol data stored in the symbol table and the context data stored in the context table, and update the symbol table and the context table.
 9. A computer-implemented method for analyzing computer code comprising: receiving computer code from a non-trusted entity via a network; building a tree representing the computer code, a node of the tree having a statement from the computer code; walking to the node of the tree and analyzing the statement to identify symbol data describing a variable, the symbol data describing a name of the variable and a value of the variable; and storing the symbol data in a symbol table.
 10. The computer-implemented method of claim 9, further comprising determining context data describing a scope of the statement and storing the context data in a context table.
 11. The computer-implemented method of claim 10, wherein the symbol data stored in the symbol table is associated with the context data stored in the context table.
 12. The computer-implemented method of claim 9, further comprising embedding a probe function in the node of the tree, detecting the probe function and calling a probe responsive to detecting the probe function in the node.
 13. The computer-implemented method of claim 9, further comprising determining whether the statement is a simple statement and executing the statement responsive to determining that the statement is the simple statement.
 14. The computer-implemented method of claim 13, wherein the simple statement includes one or more of a basic language operator applied to the variable and a function code intrinsic to a language in which the computer code is written.
 15. The computer-implemented method of claim 13, further comprising analyzing the executed statement to identify modifications to the symbol data stored in the symbol table and updating the symbol table.
 16. The computer-implemented method of claim 10, further comprising: determining whether the statement is a simple statement; executing the statement responsive to determining that the statement is the simple statement; analyzing the executed statement to identify modifications to the symbol data stored in the symbol table and the context data stored in the context table; and updating the symbol table and the context table.
 17. A computer program product comprising a computer usable storage medium including a computer readable program, the computer readable program when executed by a processor causes the processor to: build a tree representing computer code, a node of the tree having a statement from the computer code; walk to the node of the tree and analyze the statement to identify symbol data describing a variable, the symbol data describing a name of the variable and a value of the variable; and store the symbol data in a symbol table.
 18. The computer program product of claim 17, the computer readable program when executed by the processor further causing the processor to: determine context data describing a scope of the statement; and store the context data in a context table.
 19. The computer program product of claim 18, wherein the symbol data stored in the symbol table is associated with the context data stored in the context table.
 20. The computer program product of claim 17, the computer readable program when executed by the processor further causing the processor to: embed a probe function in the node of the tree; detect the probe function; and call a probe responsive to detecting the probe function in the node.
 21. The computer program product of claim 17, the computer readable program when executed by the processor further causing the processor to: determine whether the statement is a simple statement; and execute the statement responsive to determining that the statement is the simple statement.
 22. The computer program product of claim 21, wherein the simple statement includes one or more of a basic language operator applied to the variable and a function code intrinsic to a language in which the computer code is written.
 23. The computer program product of claim 21, the computer readable program when executed by the processor further causing the processor to: analyze the executed statement to identify modifications to the symbol data stored in the symbol table; and update the symbol table.
 24. The computer program product of claim 18, the computer readable program when executed by the processor further causing the processor to: determine whether the statement is a simple statement; execute the statement responsive to determining that the statement is the simple statement; analyze the executed statement to identify modifications to the symbol data stored in the symbol table and the context data stored in the context table; and update the symbol table and the context table. 